package installer.article;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class InstallArticle {
	private static JdbcTemplate jdbcTemplate;

	@BeforeClass
	public static void before() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"config/context/applicationContext.xml");
		jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
	}

	@Test
	public void install() {
		// 创建表
		try {
			String resourcesql = "id bigint PRIMARY KEY AUTO_INCREMENT,"
					+ "authority int not null," + "ownerID bigint not null,"
					+ "ownerPortrait varchar(40) not null,"
					+ "ownerNickname varchar(40) not null,"
					+ "createTime datetime not null," + "updateTime datetime not null,"
					+ "commentNum int not null," + "shareNum int not null,"
					+ "activity enum('normal','frozen','deleted','undeletable') NOT NULL not null,categoryID bigint not null,categoryName varchar(240) not null,";
			String articlesql = "title varchar(240) CHARACTER SET utf8," + "content MEDIUMTEXT CHARACTER SET utf8,"+"digest varchar(600),"
					+ "readNum int not null";
			String sql = "create table article (" + resourcesql + articlesql
					+ ")DEFAULT CHARSET=utf8;";
			jdbcTemplate.update(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
